/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;

/**
 *
 * @author karennyq
 */
public class ReadFile {

    public String[] readTextFile(String fileDirectory) throws IOException {
        File file = new File(fileDirectory);
        
        String[] textFileInfo = new String[3];
        String emailContent = "";
        String emailSubject = "";
        String line = "";

        try {
            Scanner scanner = new Scanner(file);

            while (scanner.hasNextLine()) {
                line = scanner.nextLine();
                if ((line.toLowerCase()).contains("[Email Subject]".toLowerCase())) {
                    emailSubject = scanner.nextLine();
                    textFileInfo[0] = emailSubject;
                } else if ((line.toLowerCase()).contains("[Email Contents]".toLowerCase())) {
                    while (scanner.hasNextLine()) {
                        line = scanner.nextLine();
                        if (line.isEmpty()) {
                            line = " ";
                        }
                        line = line + "<br/>" + " ";
                        emailContent = emailContent + line + " ";
                        textFileInfo[1] = emailContent;
                    }
                }
            }

            if (textFileInfo[0].isEmpty()) {
                textFileInfo[2] = "Email Subject is empty!";
                
            } else if (textFileInfo[1].isEmpty()) {
                textFileInfo[2] = "Email Content is empty!";
                
            } else {
                textFileInfo[2] = "";
            }

            return textFileInfo;
        } catch (FileNotFoundException e) {
            System.out.println(e);
            textFileInfo[2] = "Can't Find Reset Password Email Template!";
            return textFileInfo;
        }
    }
}
